<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tlds/workflow.tld" prefix="wf"%>
<%@ taglib uri="http://org.gocom.bpm.platform/tags/processgraph" prefix="p"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>流程图</title>
		<%@include file="/common.jsp"%>
		<%@include file="/common/common.jsp"%>
    	<%@include file="/coframe/tools/skins/common.jsp" %>
		<script type="text/javascript" src="<%=request.getContextPath()%>/workflow/wfcomponent/web/js/Graphic.js"></script>
	
	</head>
	<%
		String processInstId = request.getParameter("processInstId");
		String zoom = request.getParameter("zoomvalue");
		if(zoom==""||zoom==null)
		{
			zoom = "1";	
		}
	 %>
	<body style="text-align:center;">	
		<p:processGraph processInstID="<%=processInstId%>" showNote="true" zoomQuotiety="<%=zoom %>">
			 <p:activityGraph activityType="start" onclick="showStart()"/>
			 <p:activityGraph activityType="manual" onmouseover="openActivityDialog(event, this)" onclick="selectWorkItem(this)"/>
			 <p:activityGraph activityType="finish" onclick="showFinish()"/>
		</p:processGraph>
	<script type="text/javascript">
		function openActivityDialog(e, actObj){
			if(actObj.getAttribute('processInstID') == null)
				return;
			// 兼容ff、ie	
			var event = e || window.event; 
			//tips显示内容
			var strMsg = "";
			//tips显示背景
			var state = "info";
			var activityInstId =actObj.getAttribute('activityInstId');
        	var json = nui.encode({activityInstId:activityInstId});
	        $.ajax({
	            url: "com.atozsoft.wf.wfgraph.queryWorkItemById.biz.ext",
	            type: 'POST',
	            data:json,
	            cache: false,
	            async: false,
	            contentType: 'text/json',
	            success: function(text) {
	                var data = text.datas[0];
	                var currentState = data.currentState;
	                if(currentState!=4 && currentState!=10){
	                	strMsg = data.workItemName +" - " + data.partiName + " - " + data.endTime ;
	                	state = "success";
	                }else{
	                	strMsg = " 待审批： " + data.workItemName +" - " + data.partiName;
	                	state = "warning";
	                } 
	          }
	        });
     
	        /* var x = event.clientX;
	        var y = event.clientY; */
	        /* add by chenhe*/
			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = event.pageX || event.clientX + scrollX;
            var y = event.pageY || event.clientY + scrollY;
	        mini.showTips({
	            content: strMsg,
	            state: state,
	            x: x,
	            y: y,
	            timeout: 2000
	        });  
		}
		
		function showStart(){
			//tips显示内容
			var strMsg = "流程实例启动！";
			//tips显示背景
			var state = "info";
			/* var x = event.clientX;
	        var y = event.clientY; */
	        
			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = event.pageX || event.clientX + scrollX;
            var y = event.pageY || event.clientY + scrollY;
	        mini.showTips({
	            content: strMsg,
	            state: state,
	            x: x,
	            y: y,
	            timeout: 1000
	        });
		}
		
		function showFinish(){
			//tips显示内容
			var strMsg = "流程实例结束！";
			//tips显示背景
			var state = "info";
			/* var x = event.clientX;
	        var y = event.clientY; */
	        
			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = event.pageX || event.clientX + scrollX;
            var y = event.pageY || event.clientY + scrollY;
	        mini.showTips({
	            content: strMsg,
	            state: state,
	            x: x,
	            y: y,
	            timeout: 1000
	        });
		}
		
		var activityDefID = "";
		function selectWorkItem(actObj){
			if(actObj.getAttribute('processInstID') == null)
				return;
			var activityInstId =actObj.getAttribute('activityInstId');
        	var json = nui.encode({activityInstId:activityInstId});
	        $.ajax({
	            url: "com.atozsoft.wf.wfgraph.queryWorkItemById.biz.ext",
	            type: 'POST',
	            data:json,
	            cache: false,
	            async: false,
	            contentType: 'text/json',
	            success: function(text) {
	                var data = text.datas[0];
	                var currentState = data.currentState;
	                if(currentState!=4 && currentState!=10){
	                	activityDefID = data.activityDefID + "_" + data.workItemName;
	                	CloseWindow("ok"); 
	                }else{
	                	nui.alert("工作项尚未执行，请重新选择！", "提示");
	                }
	                
	          }
	        });
		}
		
		//返回数据
    	function GetData(){
    		return activityDefID;
    	}
		
		// 关闭窗体
		function CloseWindow(action){
		   if(window.CloseOwnerWindow) 
		    return window.CloseOwnerWindow(action);
		  else
		    return window.close();
		}
	</script>
    		
	</body>
</html>
